﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NetSysData;

namespace BladeTecWebApplication.Admin
{
    public partial class ViewQuestionLevels : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            //refreshes question level table
            if (!Page.IsPostBack)
            {
                NetSysData.NetSysData data = new NetSysData.NetSysData();
                //GetAttemptList_Result[] attempts = data.GetAttemptList();

                gvQuestionLevels.DataSource = data.GetQuestionLevels();
                gvQuestionLevels.DataBind();


            }
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {

            
            int result;
            NetSysData.NetSysData data = new NetSysData.NetSysData();
            
            //goes through each checkbox control, selects the value (level_id) of those that are checked, 
            //and deletes the corresponding level id from the database

            foreach (string s in Request.Form)
            {
                if (s.IndexOf("level_") == 0)
                {
                    int level_id = Int32.Parse(Request.Form.Get(s));
                    result = data.DeleteQuestionLevel(level_id);
                    if (result == -2)
                    {
                        pnlErrorDelete1.Visible = true;
                    }
                }
            }


            //refreshes question level page with updated information

            gvQuestionLevels.DataSource = data.GetQuestionLevels();
            gvQuestionLevels.DataBind();
        
        
        
        
        }
    }
}
    
